//
//  BDUserInfoViewController.m
//  BadBoy
//
//  Created by wen on 2017/6/6.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDUserInfoViewController.h"
#import "BDUserInfoTableViewCell.h"
#import "BDFMDBTool.h"
#import "BDTextFieldAlert.h"
#import "BDHomeUserViewController.h"
#import "BDCityInfo.h"
#import "BDAgrenCityChooseView.h"
#import "BDBaseUserModel.h"

@interface BDUserInfoViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *datasource;

@property (nonatomic, copy) void (^requestBlock)(BDUserInfoViewController *userVC);
@property (nonatomic, assign) BOOL isFollow;
@property (nonatomic, assign) BOOL isFriend;
@property (nonatomic, assign) BOOL isSelf;
@property (nonatomic, assign) NSInteger follow;
@property (nonatomic, assign) NSInteger follower;
@property (nonatomic, assign) NSInteger userID;
@property (nonatomic, copy) void(^guanzhuBlock)(BOOL isFollow);

@property (nonatomic, strong) UIView *bottomView;

@property (nonatomic, strong) UIButton *cancelButton;
@property (nonatomic, strong) UIButton *chatButton;
@property (nonatomic, strong) UIButton *followButton;
@property (nonatomic, strong) UIButton *followerButton;

@property (nonatomic, strong) NSString *agent_city;
@end

@implementation BDUserInfoViewController



- (instancetype)initWithUserID:(NSInteger)userID isFollow:(BOOL)isFollow guanzhuBlock:(void (^)(BOOL))guanzhuBlock{
    if (self = [super init]) {
        self.hidesBottomBarWhenPushed = YES;
        self.userID = userID;
//        self.requestBlock = requestBlock;
        self.isFollow = isFollow;
        self.guanzhuBlock = guanzhuBlock;
        
//        [self requeset];

    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = ASLocalizedString(@"个人信息");
    
    
    self.tableView.hidden = YES;
    self.bottomView.hidden = YES;
    [self requeset];
    
    [self bindRAC];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)bindRAC{
    [[self.cancelButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSString *guanzhuTitle = self.isFollow == YES ? ASLocalizedString(@"取消关注"): ASLocalizedString(@"关注");
        NSString *url = [NSString stringWithFormat:@"%@follow/%@", KBDBaseURL, @(self.userModel.user_id)];
        NSString *headValid = [BDUserModel getHeaderValidation];
        //        NSDictionary *para = @{@"id":@(self.model.my_id)};
        [MBManager showLoadingAlert:ASLocalizedString(@"请稍后")clickHidden:NO clickBlock:nil];
        RACSignal *signal = [[BDNetworkingServer yy_POST:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
        [signal subscribeNext:^(id  _Nullable x) {
//            [MBManager hideAlert];
            [MBManager showBriefAlert:[NSString stringWithFormat:ASLocalizedString(@"%@成功"), guanzhuTitle] clickHidden:NO clickBlock:nil];
            self.isFollow = [x[@"status"] boolValue];
            [_cancelButton setTitle:self.isFollow == YES ? ASLocalizedString(@"取消关注"): ASLocalizedString(@"关注")forState:UIControlStateNormal];
            [_cancelButton setImage:self.isFollow == YES ? [UIImage imageNamed:@"message_quxiaoguanzhu"] : [UIImage imageNamed:@"message_guanzhu"] forState:UIControlStateNormal];
            _cancelButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
            if (self.isFollow) {
                self.follower++;
            }else{
                self.follower--;
            }
            [self.followerButton setTitle:[NSString stringWithFormat:@"%@ %@",ASLocalizedString(@"粉丝"),@(self.follower)] forState:UIControlStateNormal];
            
            if (self.guanzhuBlock) {
                self.guanzhuBlock(self.isFollow);
            }
        }];
        
        [signal subscribeError:^(NSError * _Nullable error) {
//            [MBManager hideAlert];
            [MBManager showBriefAlert:[NSString stringWithFormat:ASLocalizedString(@"%@失败"), guanzhuTitle] clickHidden:NO clickBlock:nil];
            // BDLog(ASLocalizedString(@"关注操作失败：%@"), error);
        }];
    }];
    [[self.chatButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if ([[_chatButton titleForState:UIControlStateNormal] isEqualToString:ASLocalizedString(@"发送消息")]) {
            //1.先遍历当前是否有这个聊天，如果有，那么直接返回
            for (int i = 0; i < self.navigationController.viewControllers.count; i++) {
                UIViewController *viewController = self.navigationController.viewControllers[i];
//                if ([viewController isKindOfClass:[BDChatViewController class]]) {
//                    BDChatViewController *chatVC = (BDChatViewController *)viewController;
////                    if ([chatVC.conversation.conversationId isEqualToString:[NSString stringWithFormat:@"%@", @(self.userModel.user_id)]]) {
////                        [self.navigationController popToViewController:chatVC animated:YES];
////                        return;
////                    }
//                }
            }
            [[NSNotificationCenter defaultCenter] postNotificationName:@"jumpToNewChatVC" object:self.userModel];
        }else {
            [BDTextFieldAlert showWithTitle:ASLocalizedString(@"添加好友")placeHolder:ASLocalizedString(@"打个招呼吧")finishBlock:^(NSString *text) {
//                EMError *error = [[EMClient sharedClient].contactManager addContact:[NSString stringWithFormat:@"%@", @(self.userModel.user_id)] message:text];
//                if (!error) {
//                    [MBManager showBriefAlert:ASLocalizedString(@"请求已发送")clickHidden:NO clickBlock:nil];
//                }
            }];
        }
    }];
}

- (void)layoutSubViews{
    if (self.isSelf == YES) {
        self.bottomView.hidden = YES;
    }else{
        self.bottomView.hidden = NO;
        [self.chatButton setTitle:self.isFriend == YES ? ASLocalizedString(@"发送消息"): ASLocalizedString(@"添加好友")forState:UIControlStateNormal];
        [self.chatButton setImage:self.isFollow == YES ? [UIImage imageNamed:@"message_faxiaoxi"] : [UIImage imageNamed:@"message_tianjiahaoyou"] forState:UIControlStateNormal];
        [self.cancelButton setTitle:self.isFollow == YES ? ASLocalizedString(@"取消关注"): ASLocalizedString(@"关注")forState:UIControlStateNormal];
        [self.cancelButton setImage:self.isFollow == YES ? [UIImage imageNamed:@"message_quxiaoguanzhu"] : [UIImage imageNamed:@"message_guanzhu"] forState:UIControlStateNormal];
        self.cancelButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
    }
    [self.followButton setTitle:[NSString stringWithFormat:@"%@ %@",ASLocalizedString(@"关注"),@(self.follow)] forState:UIControlStateNormal];
    [self.followerButton setTitle:[NSString stringWithFormat:@"%@ %@",ASLocalizedString(@"粉丝"),@(self.follower)] forState:UIControlStateNormal];
}

- (void)requeset{
    [MBManager showLoadingAlert:ASLocalizedString(@"请稍后")clickHidden:NO clickBlock:nil];
    NSString *url = [NSString stringWithFormat:@"%@users/%@", KBDBaseURL, @(self.userID)];
    NSString *headValid = [BDUserModel getHeaderValidation];
    
    RACSignal *signal = [[BDNetworkingServer yy_GET:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
    [signal subscribeNext:^(id  _Nullable x) {
        BDBaseUserModel *baseUser = [BDBaseUserModel mj_objectWithKeyValues:x];
        [BDFMDBTool replaceWithObject:baseUser];
        self.userModel = [BDUserModel mj_objectWithKeyValues:x];
        BDUserModel *currentUser = [BDUserModel getCurrentUser];
        self.isSelf = currentUser.user_id == self.userModel.user_id;
    }];
    
    [signal subscribeError:^(NSError * _Nullable error) {
        [MBManager hideAlert];
        self.tableView.hidden = NO;
        [self showErrorViewWithTapBlock:^{
            [self requeset];
        }];
    }];
    
    NSString *url2 = [NSString stringWithFormat:@"%@user/%@/statistic", KBDBaseURL, @(self.userModel.user_id)];
//    NSString *headValid = [BDUserModel getHeaderValidation];
    RACSignal *signal2 = [[BDNetworkingServer yy_GET:url2 parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
    [signal2 subscribeNext:^(id  _Nullable x) {
        self.follow = [x[@"follow"] integerValue];
        self.follower = [x[@"follower"] integerValue];
        self.isFollow = [x[@"is_follow"] boolValue];
        
        //获取好友列表，获取关注列表
        if (self.isSelf == NO) {
            self.isFriend = NO;
//            NSArray *friendsList = [BDFMDBTool queryWithClass:[BDFridentInfo class]];
//            for (BDFridentInfo *friends in friendsList) {
//                if (friends.user_id.integerValue == self.userModel.user_id) {
//                    self.isFriend = YES;
//                    break;
//                }
//            }
        }
    }];
    [signal2 subscribeError:^(NSError * _Nullable error) {
        [MBManager hideAlert];
        self.tableView.hidden = NO;
        [self showErrorViewWithTapBlock:^{
            [self requeset];
        }];
    }];
    
    [[RACSignal merge:@[signal, signal2]] subscribeCompleted:^{
        [MBManager hideAlert];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.tableView.hidden = NO;
            [self requestDatasource];
            _tableView.tableHeaderView = [self customHeaderView];
            [self.tableView reloadData];
            [self layoutSubViews];
        });
    }];
}

- (void)requestDatasource{
    BDUserModel *currentUser = [BDUserModel getCurrentUser];
    /*
     这里需要分情况来处理
     1.当前用户是管理员，那么可以对该用户进行两种操作，设置为代理和开通权限
     2.当前用户是代理，那么判断查看用户归属地是否和权限处于同一个地方，如果是同一个地方可以给权限，否则不能给
     3.当前用户是正常用户，那么无法进行以上操作
     */
    
    //当对方也是管理员的时候，是无法操作的
    if (currentUser.is_admin == YES && self.userModel.is_admin == NO) {
        self.agent_city = ASLocalizedString(@"无");
        if (self.userModel.agent_city_id != 0) {
            BDCityInfo *cityInfo = [BDCityInfo getCityWithId:self.userModel.agent_city_id];

            self.agent_city = cityInfo.name;
        }
        
        self.datasource = @[@[@{@"title":ASLocalizedString(@"账号"), @"subTitle":@(self.userModel.user_id)},
                              @{@"title":ASLocalizedString(@"性别"), @"subTitle":self.userModel.sex == 1 ? ASLocalizedString(@"男"): ASLocalizedString(@"女")},
                              @{@"title":ASLocalizedString(@"生日"), @"subTitle":[self.userModel.birthday isNotEmpty] ? self.userModel.birthday : ASLocalizedString(@"保密")}],
                            @[@{@"title":ASLocalizedString(@"地区"), @"subTitle":ASLocalizedString(@"广东 广州")},
                              @{@"title":ASLocalizedString(@"个人动态"), @"subTitle":@"", @"needJiantou":@YES}],
                            @[@{@"title":ASLocalizedString(@"认证"), @"subTitle":@"", @"switch":@(self.userModel.is_auth)},
                              @{@"title":ASLocalizedString(@"代理城市"), @"subTitle":self.agent_city, @"needJiantou":@YES}]].mutableCopy;
    }
    //当对方的权限是代理或者是管理员的时候，代理是无法操作的
    else if (currentUser.is_agent == YES && (self.userModel.is_admin == NO && self.userModel.is_agent == NO)) {
        if (currentUser.agent_city_id == self.userModel.mobile_city_id) {
            self.datasource = @[@[@{@"title":ASLocalizedString(@"账号"), @"subTitle":@(self.userModel.user_id)},
                                  @{@"title":ASLocalizedString(@"性别"), @"subTitle":self.userModel.sex == 1 ? ASLocalizedString(@"男"): ASLocalizedString(@"女")},
                                  @{@"title":ASLocalizedString(@"生日"), @"subTitle":[self.userModel.birthday isNotEmpty] ? self.userModel.birthday : ASLocalizedString(@"保密")}],
                                @[@{@"title":ASLocalizedString(@"地区"), @"subTitle":ASLocalizedString(@"广东 广州")},
                                  @{@"title":ASLocalizedString(@"个人动态"), @"subTitle":@"", @"needJiantou":@YES}],
                                @[@{@"title":ASLocalizedString(@"权限"), @"subTitle":@"", @"switch":@(self.userModel.is_auth)}]].mutableCopy;
        }else {
            self.datasource = @[@[@{@"title":ASLocalizedString(@"账号"), @"subTitle":@(self.userModel.user_id)},
                                  @{@"title":ASLocalizedString(@"性别"), @"subTitle":self.userModel.sex == 1 ? ASLocalizedString(@"男"): ASLocalizedString(@"女")},
                                  @{@"title":ASLocalizedString(@"生日"), @"subTitle":[self.userModel.birthday isNotEmpty] ? self.userModel.birthday : ASLocalizedString(@"保密")}],
                                @[@{@"title":ASLocalizedString(@"地区"), @"subTitle":ASLocalizedString(@"广东 广州")},
                                  @{@"title":ASLocalizedString(@"个人动态"), @"subTitle":@"", @"needJiantou":@YES}]].mutableCopy;
        }
    }else{
        self.datasource = @[@[@{@"title":ASLocalizedString(@"账号"), @"subTitle":@(self.userModel.user_id)},
                              @{@"title":ASLocalizedString(@"性别"), @"subTitle":self.userModel.sex == 1 ? ASLocalizedString(@"男"): ASLocalizedString(@"女")},
                              @{@"title":ASLocalizedString(@"生日"), @"subTitle":[self.userModel.birthday isNotEmpty] ? self.userModel.birthday : ASLocalizedString(@"保密")}],
                            @[@{@"title":ASLocalizedString(@"地区"), @"subTitle":ASLocalizedString(@"广东 广州")},
                              @{@"title":ASLocalizedString(@"个人动态"), @"subTitle":@"", @"needJiantou":@YES}]].mutableCopy;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.datasource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.datasource[section] count];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 20)];
    sectionHeaderView.backgroundColor = [UIColor clearColor];
    return sectionHeaderView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BDUserInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"userInfo" forIndexPath:indexPath];
//    BDUserModel *user = [BDUserModel getCurrentUser];
    cell.textLabel.text = [self.datasource[indexPath.section][indexPath.row] objectForKey:@"title"];
    
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [self.datasource[indexPath.section][indexPath.row] objectForKey:@"subTitle"]];
    
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
    
    if ([self.datasource[indexPath.section][indexPath.row] objectForKey:@"needJiantou"]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
    }else if ([self.datasource[indexPath.section][indexPath.row] objectForKey:@"switch"]){
        UISwitch *aSwitch = [[UISwitch alloc] init];
        aSwitch.on = self.userModel.is_auth;
        cell.accessoryView = aSwitch;
        [[aSwitch rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
            NSString *url = nil;
            NSString *headValid = [BDUserModel getHeaderValidation];
            NSDictionary *para = nil;
            
            BDUserModel *currentUser = [BDUserModel getCurrentUser];
            if (currentUser.is_admin == YES) {
                url = [NSString stringWithFormat:@"%@users/%@/adminEdit", KBDBaseURL, @(self.userModel.user_id)];
                para = @{@"auth":@(!self.userModel.is_auth),
                         @"agent":@(self.userModel.is_agent),
                         @"agent_city_id":@(self.userModel.agent_city_id)};
            }else if (currentUser.is_agent == YES) {
                url = [NSString stringWithFormat:@"%@users/%@/agentEdit", KBDBaseURL, @(self.userModel.user_id)];
                para = @{@"auth":@(!self.userModel.is_auth)};
            }
            RACSignal *signal = [[BDNetworkingServer yy_PUT:url parameters:para validation:headValid automaticProcessingError:YES] execute:nil];
            [signal subscribeNext:^(id  _Nullable x) {
                self.userModel.is_auth = [x[@"is_auth"] boolValue];
                aSwitch.on = self.userModel.is_auth;
            }];
            [signal subscribeError:^(NSError * _Nullable error) {
                aSwitch.on = self.userModel.is_auth;
            }];
        }];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1 && indexPath.row == 1) {
        BDHomeUserViewController *homeUserVC = [[BDHomeUserViewController alloc] init];
        homeUserVC.user = self.userModel;
        [self.navigationController pushViewController:homeUserVC animated:YES];
    }else if (indexPath.section == 2 && indexPath.row == 1) {
        __weak BDUserInfoViewController *weakSelf = self;
        [BDAgrenCityChooseView showWithFinishBlock:^(NSString *cityName) {
//            if ([weakSelf.agent_city isEqualToString:cityName]) {
//                return;
//            }
            [MBManager showLoadingAlert:ASLocalizedString(@"请稍后")clickHidden:NO clickBlock:nil];
            NSMutableDictionary *para = @{@"auth":@(!weakSelf.userModel.is_auth)}.mutableCopy;
            if ([cityName isEqualToString:ASLocalizedString(@"无")]) {
                [para setObject:@(0) forKey:@"agent"];
            }else{
                BDCityInfo *cityInfo = [BDCityInfo getCityWithName:cityName type:BDCityTypeCity];
                [para setObject:@(1) forKey:@"agent"];
                [para setObject:@(cityInfo.infoID) forKey:@"agent_city_id"];
            }
            NSString *url = [NSString stringWithFormat:@"%@users/%@/adminEdit", KBDBaseURL, @(self.userModel.user_id)];
            NSString *headValid = [BDUserModel getHeaderValidation];
            RACSignal *signal = [[BDNetworkingServer yy_PUT:url parameters:para validation:headValid automaticProcessingError:YES] execute:nil];
            [signal subscribeNext:^(id  _Nullable x) {
                [MBManager hideAlert];
                weakSelf.userModel.is_agent = [x[@"is_agent"] boolValue];
                weakSelf.userModel.is_auth = [x[@"is_auth"] boolValue];
                if (weakSelf.userModel.is_agent == NO) {
                    weakSelf.userModel.agent_city_id = 0;
                }else{
                    weakSelf.userModel.agent_city_id = [para[@"agent_city_id"] integerValue];
                }
                [weakSelf requestDatasource];
                [weakSelf.tableView reloadData];
            }];
            [signal subscribeError:^(NSError * _Nullable error) {
//                [MBManager hideAlert];
                [MBManager showBriefAlert:ASLocalizedString(@"修改失败")clickHidden:YES clickBlock:nil];
            }];
        }];
    }
}

- (UITableView *)tableView{
    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kBDTopHeight, kBDScreenWidth, kBDScreenHeight - kBDTopHeight - self.bottomView.height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[BDUserInfoTableViewCell class] forCellReuseIdentifier:@"userInfo"];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorInset = UIEdgeInsetsZero;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (UIView *)customHeaderView{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 100)];
    headView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.userModel.cover] placeholderImage:[UIImage imageNamed:@"avatar"]];
    imageView.size = CGSizeMake(60, 60);
    imageView.left = 15;
    imageView.centerY = headView.height / 2.0;
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = imageView.width / 2.0;
    [headView addSubview:imageView];
    
    UILabel *nikeLabel = [[UILabel alloc] init];
    nikeLabel.text = self.userModel.nickname;
    nikeLabel.font = [UIFont systemFontOfSize:17];
    nikeLabel.textColor = [UIColor colorWithHexString:@"#101010"];
    [nikeLabel sizeToFit];
    nikeLabel.left = imageView.right + 15;
    nikeLabel.bottom = headView.height / 2.0 - 3;
    [headView addSubview:nikeLabel];
    
    UIImageView *levelImageView = [[UIImageView alloc] init];
    levelImageView.left = nikeLabel.right + 5;
    levelImageView.size = CGSizeMake(22 / 2, 26 / 2);
    levelImageView.centerY = nikeLabel.centerY;
    levelImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"leve%ld",[self.userModel.points[@"level"] integerValue]]];
    [headView addSubview:levelImageView];
    
    UIImageView *vipImageView = [[UIImageView alloc] init];
    vipImageView.left = levelImageView.right + 5;
    vipImageView.size = CGSizeMake(34 / 2, 25 / 2);
    vipImageView.centerY = levelImageView.centerY;
    vipImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"showVip%ld",self.userModel.vip_level]];
    [headView addSubview:vipImageView];
    
    self.followButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _followButton.frame = CGRectMake(0, 0, 60, 30);
    _followButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_followButton setTitleColor:[UIColor colorWithHexString:@"#808080"] forState:UIControlStateNormal];
    [_followButton setTitle:[NSString stringWithFormat:@"%@ 0",ASLocalizedString(@"关注")] forState:UIControlStateNormal];
    _followButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _followButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    _followButton.width = [[_followButton titleForState:UIControlStateNormal] widthWithFont:_followButton.titleLabel.font];
    _followButton.left = nikeLabel.left;
    _followButton.top = headView.height / 2.0 + 3;
    [headView addSubview:_followButton];
    
    self.followerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _followerButton.frame = CGRectMake(0, 0, 60, 30);
    _followerButton.left = _followButton.right + 10;
    _followerButton.titleLabel.font = [UIFont systemFontOfSize:14];
    _followerButton.top = headView.height / 2.0 + 3;;
    [_followerButton setTitleColor:[UIColor colorWithHexString:@"#808080"] forState:UIControlStateNormal];
    [_followerButton setTitle:[NSString stringWithFormat:@"%@ 0",ASLocalizedString(@"粉丝")] forState:UIControlStateNormal];
    _followerButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _followerButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:_followerButton];
    
    return headView;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kBDScreenWidth, kBDButtonHeight)];
        _bottomView.bottom = kBDScreenHeight;
        _bottomView.backgroundColor = [UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:1.0f];
        [_bottomView addSubview:self.cancelButton];
        [_bottomView addSubview:self.chatButton];
        
        NSArray *buttonArr = @[self.cancelButton, self.chatButton];
        
        for (int i = 0; i < buttonArr.count; i++) {
            UIButton *button = buttonArr[i];
            button.frame = CGRectMake(kBDScreenWidth / 2.0 * i, 0, kBDScreenWidth / 2.0, _bottomView.height);
            
            if (i > 0) {
                UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, _bottomView.height / 2.0)];
                line.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
                line.centerY = _bottomView.height / 2.0;
                line.centerX = _bottomView.width / 2.0;
                [_bottomView addSubview:line];
            }
        }
        [self.view addSubview:_bottomView];
    }
    return _bottomView;
}

- (UIButton *)cancelButton{
    if (!_cancelButton) {
        self.cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(0, kBDScreenHeight - kBDButtonHeight, kBDScreenWidth/2, kBDButtonHeight)];
        _cancelButton.backgroundColor = [UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:1.0f];
        _cancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_cancelButton setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
        //        [_cancelButton setTitle:ASLocalizedString(@"取消关注")forState:UIControlStateSelected];
        [_cancelButton setImage:[UIImage imageNamed:@"message_guanzhu"] forState:UIControlStateNormal];
        //        [_cancelButton setImage:[UIImage imageNamed:@"message_quxiaoguanzhu"] forState:UIControlStateNormal];
    }
    return _cancelButton;
}

- (UIButton *)chatButton{
    if (!_chatButton) {
        self.chatButton = [[UIButton alloc]initWithFrame:CGRectMake(kBDScreenWidth/2, kBDScreenHeight-kBDButtonHeight, kBDScreenWidth/2, kBDButtonHeight)];
        _chatButton.backgroundColor = [UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:1.0f];
        _chatButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_chatButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_chatButton setTitle:ASLocalizedString(@"添加好友")forState:UIControlStateNormal];
        //        [_chatButton setImage:[UIImage imageNamed:@"message_faxiaoxi"] forState:UIControlStateSelected];
        [_chatButton setImage:[UIImage imageNamed:@"message_tianjiahaoyou"] forState:UIControlStateNormal];
        _chatButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        [_chatButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _chatButton;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
